﻿using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using APP.HELPER.Data.Helper;
using APP.HELPER.Utils.CustomizeToolbox;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using ComboBox = System.Windows.Forms.ComboBox;

namespace Dictionary.ERP
{
    public class HRM_BRANCH
    {
        private string m_Address;
        private string m_BranchCode;
        private string m_BranchName;
        private string m_Description;
        private int m_FactQuantity;
        private string m_Fax;
        private decimal m_MinimumSalary;
        private string m_PersonName;
        private string m_Phone;
        private int m_Quantity;

        public HRM_BRANCH()
        {
            m_BranchCode = "";
            m_BranchName = "";
            m_Address = "";
            m_Phone = "";
            m_Fax = "";
            m_MinimumSalary = 0M;
            m_PersonName = "";
            m_Quantity = 0;
            m_FactQuantity = 0;
            m_Description = "";
        }

        public HRM_BRANCH(string BranchCode, string BranchName, string Address, string Phone, string Fax,
            decimal MinimumSalary, string PersonName, int Quantity, int FactQuantity, string Description)
        {
            m_BranchCode = BranchCode;
            m_BranchName = BranchName;
            m_Address = Address;
            m_Phone = Phone;
            m_Fax = Fax;
            m_MinimumSalary = MinimumSalary;
            m_PersonName = PersonName;
            m_Quantity = Quantity;
            m_FactQuantity = FactQuantity;
            m_Description = Description;
        }

        [DisplayName("Address"), Category("Column")]
        public string Address
        {
            get { return m_Address; }
            set { m_Address = value; }
        }

        [Category("Primary Key"), DisplayName("BranchCode")]
        public string BranchCode
        {
            get { return m_BranchCode; }
            set { m_BranchCode = value; }
        }

        [DisplayName("BranchName"), Category("Column")]
        public string BranchName
        {
            get { return m_BranchName; }
            set { m_BranchName = value; }
        }

        [Category("Column"), DisplayName("Description")]
        public string Description
        {
            get { return m_Description; }
            set { m_Description = value; }
        }

        [Category("Column"), DisplayName("FactQuantity")]
        public int FactQuantity
        {
            get { return m_FactQuantity; }
            set { m_FactQuantity = value; }
        }

        [Category("Column"), DisplayName("Fax")]
        public string Fax
        {
            get { return m_Fax; }
            set { m_Fax = value; }
        }

        [DisplayName("MinimumSalary"), Category("Column")]
        public decimal MinimumSalary
        {
            get { return m_MinimumSalary; }
            set { m_MinimumSalary = value; }
        }

        [DisplayName("PersonName"), Category("Column")]
        public string PersonName
        {
            get { return m_PersonName; }
            set { m_PersonName = value; }
        }

        [DisplayName("Phone"), Category("Column")]
        public string Phone
        {
            get { return m_Phone; }
            set { m_Phone = value; }
        }

        public string ProductName
        {
            get { return "Class HRM_BRANCH"; }
        }

        public string ProductVersion
        {
            get { return "1.0.0.0"; }
        }

        [DisplayName("Quantity"), Category("Column")]
        public int Quantity
        {
            get { return m_Quantity; }
            set { m_Quantity = value; }
        }

        public void AddCombo(ComboBox combo)
        {
            GridCalendarControlLib.TableToComboBox(combo, GetList(), "BranchName", "BranchCode");
        }

        public void AddComboAll(ComboBox combo)
        {
            var list = new DataTable();
            list = GetList();
            DataRow row = list.NewRow();
            row["BranchCode"] = "All";
            row["BranchName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            GridCalendarControlLib.TableToComboBox(combo, list, "BranchName", "BranchCode");
        }

        public void AddComboEdit(ComboBoxEdit combo)
        {
            var list = new DataTable();
            list = GetList();
            foreach (DataRow row in list.Rows)
            {
                combo.Properties.Items.Add(row["BranchName"]);
            }
        }

        public void AddGridLookupEdit(GridLookUpEdit gridlookup)
        {
            var list = new DataTable();
            list = GetList();
            gridlookup.Properties.DataSource = list;
            gridlookup.Properties.DisplayMember = "BranchName";
            gridlookup.Properties.ValueMember = "BranchCode";
        }

        public void AddGridLookupEdit(GridLookUpEdit gridlookup, string ValueMember)
        {
            var list = new DataTable();
            list = GetList();
            gridlookup.Properties.DataSource = list;
            gridlookup.Properties.DisplayMember = "BranchName";
            gridlookup.Properties.ValueMember = ValueMember;
        }

        public void AddImageComboBoxEdit(ImageComboBoxEdit imgCombo)
        {
            imgCombo.Properties.Items.Clear();
            var list = new DataTable();
            list = GetList();
            var item = new ImageComboBoxItem
            {
                Description = "<Tất cả chi nh\x00e1nh>",
                Value = ""
            };
            imgCombo.Properties.Items.Add(item);
            foreach (DataRow row in list.Rows)
            {
                var item2 = new ImageComboBoxItem
                {
                    Description = row["BranchName"].ToString(),
                    Value = row["BranchCode"].ToString()
                };
                imgCombo.Properties.Items.Add(item2);
            }
            imgCombo.SelectedIndex = 0;
        }

        public string Delete()
        {
            string[] myParams = {"@BranchCode"};
            object[] myValues = {m_BranchCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_BRANCH_Delete", myParams, myValues);
        }

        public string Delete(string BranchCode)
        {
            string[] myParams = {"@BranchCode"};
            object[] myValues = {BranchCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_BRANCH_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string BranchCode)
        {
            string[] myParams = {"@BranchCode"};
            object[] myValues = {BranchCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_BRANCH_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string BranchCode)
        {
            string[] myParams = {"@BranchCode"};
            object[] myValues = {BranchCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_BRANCH_Delete", myParams, myValues);
        }

        public bool Exist(string BranchCode)
        {
            bool hasRows = false;
            string[] myParams = {"@BranchCode"};
            object[] myValues = {BranchCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_BRANCH_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string BranchCode)
        {
            string str = "";
            string[] myParams = {"@BranchCode"};
            object[] myValues = {BranchCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_BRANCH_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_BranchCode = Convert.ToString(reader["BranchCode"]);
                    m_BranchName = Convert.ToString(reader["BranchName"]);
                    m_Address = Convert.ToString(reader["Address"]);
                    m_Phone = Convert.ToString(reader["Phone"]);
                    m_Fax = Convert.ToString(reader["Fax"]);
                    m_MinimumSalary = Convert.ToDecimal(reader["MinimumSalary"]);
                    m_PersonName = Convert.ToString(reader["PersonName"]);
                    m_Quantity = Convert.ToInt32(reader["Quantity"]);
                    m_FactQuantity = Convert.ToInt32(reader["FactQuantity"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string PositionCode)
        {
            string str = "";
            string[] myParams = {"@BranchCode"};
            object[] myValues = {BranchCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "HRM_BRANCH_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_BranchCode = Convert.ToString(reader["BranchCode"]);
                    m_BranchName = Convert.ToString(reader["BranchName"]);
                    m_Address = Convert.ToString(reader["Address"]);
                    m_Phone = Convert.ToString(reader["Phone"]);
                    m_Fax = Convert.ToString(reader["Fax"]);
                    m_MinimumSalary = Convert.ToDecimal(reader["MinimumSalary"]);
                    m_PersonName = Convert.ToString(reader["PersonName"]);
                    m_Quantity = Convert.ToInt32(reader["Quantity"]);
                    m_FactQuantity = Convert.ToInt32(reader["FactQuantity"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string BranchCode)
        {
            string str = "";
            string[] myParams = {"@BranchCode"};
            object[] myValues = {BranchCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "HRM_BRANCH_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_BranchCode = Convert.ToString(reader["BranchCode"]);
                    m_BranchName = Convert.ToString(reader["BranchName"]);
                    m_Address = Convert.ToString(reader["Address"]);
                    m_Phone = Convert.ToString(reader["Phone"]);
                    m_Fax = Convert.ToString(reader["Fax"]);
                    m_MinimumSalary = Convert.ToDecimal(reader["MinimumSalary"]);
                    m_PersonName = Convert.ToString(reader["PersonName"]);
                    m_Quantity = Convert.ToInt32(reader["Quantity"]);
                    m_FactQuantity = Convert.ToInt32(reader["FactQuantity"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            var helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_BRANCH_GetList");
        }

        public string Insert()
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                m_BranchCode, m_BranchName, m_Address, m_Phone, m_Fax, m_MinimumSalary, m_PersonName,
                m_Quantity, m_FactQuantity, m_Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_BRANCH_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                m_BranchCode, m_BranchName, m_Address, m_Phone, m_Fax, m_MinimumSalary, m_PersonName,
                m_Quantity, m_FactQuantity, m_Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_BRANCH_Insert", myParams, myValues);
        }

        public string Insert(string BranchCode, string BranchName, string Address, string Phone, string Fax,
            decimal MinimumSalary, string PersonName, int Quantity, int FactQuantity, string Description)
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                BranchCode, BranchName, Address, Phone, Fax, MinimumSalary, PersonName, Quantity,
                FactQuantity, Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_BRANCH_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string BranchCode, string BranchName, string Address,
            string Phone, string Fax, decimal MinimumSalary, string PersonName, int Quantity, int FactQuantity,
            string Description)
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                BranchCode, BranchName, Address, Phone, Fax, MinimumSalary, PersonName, Quantity,
                FactQuantity, Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_BRANCH_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string BranchCode, string BranchName, string Address,
            string Phone, string Fax, decimal MinimumSalary, string PersonName, int Quantity, int FactQuantity,
            string Description)
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                BranchCode, BranchName, Address, Phone, Fax, MinimumSalary, PersonName, Quantity,
                FactQuantity, Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_BRANCH_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("HRM_BRANCH", "BranchCode", "CN");
        }

        public string Update()
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                m_BranchCode, m_BranchName, m_Address, m_Phone, m_Fax, m_MinimumSalary, m_PersonName,
                m_Quantity, m_FactQuantity, m_Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_BRANCH_Update", myParams, myValues);
        }

        public string Update(string BranchCode, string BranchName, string Address, string Phone, string Fax,
            decimal MinimumSalary, string PersonName, int Quantity, int FactQuantity, string Description)
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                BranchCode, BranchName, Address, Phone, Fax, MinimumSalary, PersonName, Quantity,
                FactQuantity, Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_BRANCH_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string BranchCode, string BranchName, string Address,
            string Phone, string Fax, decimal MinimumSalary, string PersonName, int Quantity, int FactQuantity,
            string Description)
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                BranchCode, BranchName, Address, Phone, Fax, MinimumSalary, PersonName, Quantity,
                FactQuantity, Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_BRANCH_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string BranchCode, string BranchName, string Address,
            string Phone, string Fax, decimal MinimumSalary, string PersonName, int Quantity, int FactQuantity,
            string Description)
        {
            string[] myParams =
            {
                "@BranchCode", "@BranchName", "@Address", "@Phone", "@Fax", "@MinimumSalary",
                "@PersonName", "@Quantity", "@FactQuantity", "@Description"
            };
            object[] myValues =
            {
                BranchCode, BranchName, Address, Phone, Fax, MinimumSalary, PersonName, Quantity,
                FactQuantity, Description
            };
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_BRANCH_Update", myParams, myValues);
        }
    }
}